package edu.tgc.service.system;

import java.util.HashMap;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import edu.tgc.entity.file.dictionary.FileDocType;
import edu.tgc.entity.system.SysDept;
import edu.tgc.repository.file.FileDocTypeRepository;
import edu.tgc.repository.system.SysDeptRepository;

@Service
public class SysPropertiesService implements InitializingBean {


    @Autowired
    protected FileDocTypeRepository fileDocTypeRepository;

    @Autowired
    protected SysDeptRepository sysDeptRepository;

    @Value(value = "${defaultPassword}")
    public String defaultPassword;

    @Value(value = "${devMode.code}")
    public String devModeCode;

    private SysDept rootDept;

    public SysDept getRootDept() {
        return rootDept;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        Constant.fileDocTypeMap = new HashMap<>();
        for (FileDocType fileDocType : this.fileDocTypeRepository.findAll()) {
            Constant.fileDocTypeMap.put(fileDocType.getSort(), fileDocType);
        }
        this.rootDept = sysDeptRepository.findByParentIsNull();
    }

    public String getDefaultPassword() {
        return this.defaultPassword;
    }

    public String getDevModeCode() {
        return this.devModeCode;
    }

    public void setDefaultPassword(String defaultPassword) {
        this.defaultPassword = defaultPassword;
    }

    public void setDevModeCode(String devModeCode) {
        this.devModeCode = devModeCode;
    }

}
